package com.ysj.demo.accompanynetwork.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ysj.demo.accompanynetwork.R;
import com.ysj.demo.accompanynetwork.bean.IntegralRecordBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 积分变动适配器
 * Created by 80530 on 2018/8/3.
 */

public class ItemIntegralAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<IntegralRecordBean> mList;
    private LayoutInflater mLayoutInflater;

    public ItemIntegralAdapter(Context context, List<IntegralRecordBean> list) {
        this.mContext = context;
        this.mList = list;
        this.mLayoutInflater = LayoutInflater.from(mContext);
    }

    public void clearList() {
        if (null != mList) {
            mList.clear();
            notifyDataSetChanged();
        }
    }

    public void addList(List<IntegralRecordBean> otherList) {
        if (null == mList) {
            mList = new ArrayList<>();
        }
        mList.addAll(otherList);
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mLayoutInflater.inflate(R.layout.item_payout_layout, parent, false);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyHolder) {
            MyHolder holder1 = (MyHolder) holder;
            IntegralRecordBean item = mList.get(position);
            switch (Integer.valueOf(item.getConsumesource())) {
                //充值
                case 1:
                    holder1.iconTv.setSelected(false);
                    break;
                //消费
                case 2:
                    holder1.iconTv.setSelected(true);
                    break;
                default:

                    break;
            }
            holder1.typeTv.setText(item.getConsumesource());
            holder1.iconTv.setText("+" + item.getConsumesum());
            holder1.dateTv.setText(item.getConsumedate());
            holder1.remarkTv.setText(item.getRemark());
        }

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    //定义内部类继承ViewHolder
    class MyHolder extends RecyclerView.ViewHolder {
        private TextView typeTv, iconTv, dateTv, remarkTv;

        public MyHolder(View view) {
            super(view);
            typeTv = view.findViewById(R.id.type_tv);
            iconTv = view.findViewById(R.id.icon_tv);
            dateTv = view.findViewById(R.id.date_tv);
            remarkTv = view.findViewById(R.id.remark_tv);
        }
    }


}
